using System.Web;
using System.Web.Security;


namespace  Source.Web.FrameWork
{
    public interface IStateProvider
    {
        void Store(string key, object value);
        T Retrieve<T>(string key) where T : class;
    }

    public class WebStateProvider : IStateProvider
    {
        public void Store(string key, object value)
        {
            HttpContext.Current.Session[key] = value;
        }

        public T Retrieve<T>(string key) where T : class
        {
            T value = HttpContext.Current.Session[key] as T;

            if (value == null)
            {
               // LogManager.WriteDebugLogEntry(string.Format("Object with key {0} not found in session and triggered a signout.", key));
                FormsAuthentication.SignOut();
                return null;
            }

            return (T)HttpContext.Current.Session[key];
        }
    }
}